﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.Services;
using AjaxControlToolkit;
using NetDon.OA.Interface;
using NetDon.Utilities;

namespace NetDon.OA.Portal
{
    /// <summary>
    /// Summary description for CascadingService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.Web.Script.Services.ScriptService]
    public class CascadingService : System.Web.Services.WebService
    {
  

        /// <summary>
        /// 获取省份数据
        /// </summary>
        /// <param name="knownCategoryValues"></param>
        /// <param name="category"></param>
        /// <returns></returns>
        [WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public CascadingDropDownNameValue[] GetProvinceContents(string knownCategoryValues, string category)
        {

            var shippingService = ServiceContainer.GetService<ILocationService>();
            return
                shippingService.GetProvinces().Select(
                    entity => new CascadingDropDownNameValue(entity.Name, entity.ProvinceId)).
                    ToArray();
        }
        /// <summary>
        /// 获取市数据
        /// </summary>
        /// <param name="knownCategoryValues"></param>
        /// <param name="category"></param>
        /// <returns></returns>
        [WebMethod]
        public CascadingDropDownNameValue[] GetCityContents(string knownCategoryValues, string category)
        {
            // Get a dictionary of known category/value pairs
            StringDictionary knownCategoryValuesDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            var province = knownCategoryValuesDictionary["Province"];
            if (string.IsNullOrEmpty(province))
            {
                return null;
            }
            var shippingService = ServiceContainer.GetService<ILocationService>();
            return shippingService.GetCities(province).Select(
                entity => new CascadingDropDownNameValue(entity.Name, entity.CityId)).ToArray();
        }
        /// <summary>
        /// 获取乡镇数据
        /// </summary>
        /// <param name="knownCategoryValues"></param>
        /// <param name="category"></param>
        /// <returns></returns>
        [WebMethod]
        public CascadingDropDownNameValue[] GetAreaContents(string knownCategoryValues, string category)
        {
            // Get a dictionary of known category/value pairs
            StringDictionary knownCategoryValuesDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            var city = knownCategoryValuesDictionary["City"];
            if (string.IsNullOrEmpty(city))
            {
                return null;
            }
            var shippingService = ServiceContainer.GetService<ILocationService>();
            return shippingService.GetAreas(city).Select(
                entity => new CascadingDropDownNameValue(entity.Name, entity.AreaId)).ToArray();
        }

        [WebMethod]
        public string[] GetIssuingOrderAddress(string prefixText, int count)
        {
            // Get a dictionary of known category/value pairs

            if (string.IsNullOrEmpty(prefixText))
            {
                return new string[0];
            }
            var orderService = ServiceContainer.GetService<IIssuingOrderService>();
            return orderService.GetIssuingOrderAddress(prefixText, count);
        }


         [WebMethod]
        public string[] GetOrderCode(string prefixText, int count)
        {
            // Get a dictionary of known category/value pairs

            if (string.IsNullOrEmpty(prefixText))
            {
                return new string[0];
            }
            var orderService = ServiceContainer.GetService<IIssuingOrderService>();
            return orderService.GetIssuingOrderByOrderCode(prefixText, count);
        }
        
    }
}
